﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using FarseerPhysics.Dynamics;
using FarseerPhysics.Factories;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using FarseerPhysics.SamplesFramework;

namespace game
{
    public class CSprite
    {
        // Ciało fizyczne, z farseera.
        public Body Body;

        //Tekstura spriata.
        public Texture2D Texture;

        public CSprite(World world, Texture2D spriteTexture, Vector2 position, bool bIsStatic)
        {
            Texture = spriteTexture;
            _origin = new Vector2(Texture.Width / 2.0f, Texture.Height / 2.0f);

            Body = BodyFactory.CreateRectangle(world, ConvertUnits.ToSimUnits(Texture.Width),
                ConvertUnits.ToSimUnits(Texture.Height), 1.0f, ConvertUnits.ToSimUnits(position));

            if (bIsStatic)
                Body.BodyType = BodyType.Static;
            else
                Body.BodyType = BodyType.Dynamic;

            Body.Restitution = DefaultVar.fObjectRestitution;
            Body.Friction = DefaultVar.fObjectFriction;
        }

        /// <summary>
        /// Metoda rysowania sprita.
        /// </summary>
        /// <param name="spriteBatch"></param>
        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Begin();
            spriteBatch.Draw(Texture, ConvertUnits.ToDisplayUnits(Body.Position), null, Color.White, 
                Body.Rotation, _origin, 1.01f, SpriteEffects.None, 0.0f);
            spriteBatch.End();
        }

        // Pozycja od której ma zacząć rysowanie.
        private Vector2 _origin;
    }
}
